package com.tencent.txcc.web.controller;

import com.baomidou.mybatisplus.plugins.Page;
import com.tencent.txcc.domain.Blacklist;
import com.tencent.txcc.dto.BlackListDto;
import com.tencent.txcc.query.BlacklistQuery;
import com.tencent.txcc.result.JSONResult;

import com.tencent.txcc.result.PageList;
import com.tencent.txcc.service.IBlacklistService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/blacklist")
public class BlacklistController {

    @Autowired
    public IBlacklistService blacklistService;


    @RequestMapping(value = "/findBlackUser",method = RequestMethod.GET)
    public JSONResult findBlackUser(@RequestBody BlackListDto blackListDto){
        return JSONResult.success(blacklistService.findBlackUser(blackListDto));
    }





    /**
    * 保存和修改公用的
    */
    @RequestMapping(value="/save",method= RequestMethod.POST)
    public JSONResult saveOrUpdate(@RequestBody Blacklist blacklist){
        if(blacklist.getId()!=null){
            blacklistService.updateById(blacklist);
        }else{
            blacklistService.insert(blacklist);
        }
        return JSONResult.success();
    }

    /**
    * 删除对象
    */
    @RequestMapping(value="/{id}",method=RequestMethod.DELETE)
    public JSONResult delete(@PathVariable("id") Long id){
        blacklistService.deleteById(id);
        return JSONResult.success();
    }

    /**
   * 获取对象
   */
    @RequestMapping(value = "/{id}",method = RequestMethod.GET)
    public JSONResult get(@PathVariable("id")Long id){
        return JSONResult.success(blacklistService.selectById(id));
    }


    /**
    * 查询所有对象
    */
    @RequestMapping(value = "/list",method = RequestMethod.GET)
    public JSONResult list(){
        return JSONResult.success(blacklistService.selectList(null));
    }


    /**
    * 带条件分页查询数据
    */
    @RequestMapping(value = "/pagelist",method = RequestMethod.POST)
    public JSONResult page(@RequestBody BlacklistQuery query){
        Page<Blacklist> page = new Page<Blacklist>(query.getPage(),query.getRows());
        page = blacklistService.selectPage(page);
        return JSONResult.success(new PageList<Blacklist>(page.getTotal(),page.getRecords()));
    }
}
